home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-04 | 1.8 KB | 72 lines | [TEXT/MPS ] |
- /*
- File: icm1.c
- Contains: Picture Compression Functions
- Written by: DTS and QT Engineering
- Copyright: © 1992-1994 by Apple Computer, Inc., all rights reserved.
- Change History (most recent first):
- <1> 12/4/94 khs changed the format of the file to the new look and feel
- To Do:
- */
-
-
- // INCLUDE FILES
- #include "icm.h"
-
-
- // FUNCTIONS
- PicHandle GetQTCompressedPict(CGrafPtr port)
- {
- long maxCompressedSize = 0;
- Handle compressedDataH = nil;
- Ptr compressedDataP;
- ImageDescriptionHandle imageDescH = nil;
- OSErr theErr;
- PicHandle myPic = nil;
- Rect bounds = port->portRect;
- PixMapHandle myPixMap = port->portPixMap;
- CodecType theCodecType = 'jpeg';
- CodecComponent theCodec = (CodecComponent)anyCodec;
- CodecQ spatialQuality = codecNormalQuality;
- short depth = 0; // let ICM choose depth
-
-
- theErr = GetMaxCompressionSize(myPixMap, &bounds, depth, spatialQuality, theCodecType,
- (CompressorComponent)theCodec, &maxCompressedSize);
- if (theErr)
- return nil;
-
- imageDescH = (ImageDescriptionHandle)NewHandle(4);
- compressedDataH = NewHandle(maxCompressedSize);
- if (compressedDataH != nil && imageDescH != nil)
- {
- MoveHHi(compressedDataH);
- HLock(compressedDataH);
- compressedDataP = StripAddress(*compressedDataH);
-
- theErr = CompressImage(myPixMap, &bounds, spatialQuality, theCodecType, imageDescH,
- compressedDataP);
-
- if (theErr == noErr)
- {
- ClipRect(&bounds);
- myPic = OpenPicture(&bounds);
- theErr = DecompressImage(compressedDataP, imageDescH, myPixMap, &bounds, &bounds,
- srcCopy, nil);
- ClosePicture();
- }
- if (theErr || GetHandleSize((Handle)myPic) == sizeof(Picture))
- {
- KillPicture(myPic);
- myPic = nil;
- }
- }
- if (imageDescH)
- DisposeHandle((Handle)imageDescH);
- if (compressedDataH)
- DisposeHandle(compressedDataH);
-
- return myPic;
- }
-
-
-